import 'package:flutter/material.dart';

class CheckBoxDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CheckBoxStateDemo();
  }
}

class CheckBoxStateDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return CheckBoxState();
  }
}

class CheckBoxState extends State<CheckBoxStateDemo> {
  bool _isSelectA = false;
  bool _isSelectB = false;

  bool _isSelectList = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('CheckBoxDemo'),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(8.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Checkbox(
                  value: _isSelectA,
                  onChanged: (value) {
                    setState(() {
                      _isSelectA = value;
                    });
                  },
                  activeColor: Colors.red,
                ),
                Checkbox(
                  value: _isSelectB,
                  onChanged: (value) {
                    setState(() {
                      _isSelectB = value;
                    });
                  },
                  activeColor: Colors.blue,
                ),
              ],
            ),
            CheckboxListTile(
              value: _isSelectList,
              title: Text('CheckBox Item A'),
              subtitle: Text('description'),
              secondary: Icon(Icons.bookmark),
              //选中之后全部改变状态
              selected: _isSelectList,
              activeColor: Colors.lightBlue,
              onChanged: (value) {
                setState(() {
                  _isSelectList = value;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
